package Acwing.数学知识;

import java.util.Scanner;

/**
 * @Title: myGcd2
 * @Author 贾金博
 * @Package Acwing.数学知识
 * @Date 2025/4/11 下午6:01
 * @description: 自己去写gcd
 */
public class myGcd2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t -- > 0 ) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            System.out.println(gcd(n, m));
        }
    }

    // 求两个数的最大公因数
    private static int gcd(int n, int m) {
        if(m == 0) {
            return n;
        }
        return gcd(m, n % m);
    }
}
